package com.shop.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author WuLiangHang
 */
@WebFilter("/*")
public class EncodingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //解决中文乱码问题，这样Servlet中就不需要再加入此代码
        servletResponse.setContentType("text/html;charset=UTF-8");
        servletRequest.setCharacterEncoding("UTF-8");
        //放行，让该请求继续往下走。代表通过本次过滤。
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}
